#include <iostream>
using namespace std;

// 加号运算符重载
class Person
{
public:
    //1、成员函数重载+号
    
    // Person operator+(Person& p)
    // {
    //     Person temp;
    //     temp.age = this->age + p.age;
    //     temp.money = this->money + p.money;

    //     return temp;
    // }
    
    int age;
    int money;
};

//2、全局函数重载+号
Person operator+(Person& p1, Person& p2)
{
    Person temp;
    temp.age = p1.age + p2.age;
    temp.money = p2.money + p1.money;

    return temp;
}

//函数重载版本
Person operator+(Person& p, int num)
{
    Person temp;
    temp.age = p.age + num;
    temp.money = p.money + num;

    return temp;
}

void test1()
{
    Person p1, p2;

    p1.age = 20;
    p1.money = 300;
    
    p2.age = 30;
    p2.money = 5000;

    //成员函数重载本质调用：  Person p3 = p1.operator+(p2);
    //全局函数重载本质调用：  Person p3 = operater+(p1,p2);
    Person p3 = p2 + p1;
    cout << "p3.age = " << p3.age << endl;
    cout << "p3.money = " << p3.money << endl;

    
    //运算符重载，也可以发生函数重载
    Person p4 = p1 + 10;
    cout << "p4.age = " << p4.age << endl;
    cout << "p4.money = " << p4.money << endl;
    
}



int main()
{
    test1();
    
    return 0;
}